package test.socket;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

import org.junit.Test;

import hyl.base.net.IData1;
import hyl.base.net.udp.UdpService;
import hyl.core.MyDate;
import hyl.core.fun.MyHostInfo;

import hyl.core.net.MyUdp;
import hyl.core.safe.MyBase64;

public class testUdpclient {
	public static void main(String [] arg) {
		new testUdpclient(). test1_3(); //.test1_2() ;
		
	}
	//@Test
	public void test1() {
		UdpService uclient=new UdpService(1000);
		byte[] bytes=MyHostInfo.instance().getHashBytes();
		System.out.println(bytes.length);
		String s=MyBase64.encode(bytes);
		System.out.println(s);
		uclient.send("127.0.0.1", 8989, IData1.B类型_数据 , bytes);
	}
	@Test
	public void test1_2() {
		
		if (MyUdp.ping("localhost", 90))
			System.out.println("可以互通");
		MyUdp udp=new MyUdp();
		SocketAddress netip=	new InetSocketAddress("localhost", 90);
		for(int i=0;i<100;i++) {
			udp.sendUtf8(netip, "test"+i);
			System.out.println(i);
			MyDate.sleep(1000);
		}
	}
public void test1_3() {
		
		if (MyUdp.ping("localhost", 90))
			System.out.println("可以互通");
		MyUdp udp=new MyUdp();
		SocketAddress netip=	new InetSocketAddress("localhost", 90);
		udp.sendUtf8(netip, "123456789012345678901234567890");
		udp.sendUtf8(netip, "123456789012345678901234567890");
	}
}
